package com.irun.ibuffet.utils;

import android.app.Activity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.ForegroundColorSpan;

/***
 * @author huangsm
 * @date 2013-2-20
 * @email huangsanm@gmail.com
 * @desc 全局方法
 */
public class Globals {

	/**
	 * 网络是否已经连接
	 * @param context
	 * @return
	 */
	public static boolean isConnection(Activity activity) {
		ConnectivityManager connectivity = (ConnectivityManager) activity
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo info = connectivity
				.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
		NetworkInfo mobile = connectivity
				.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
		if (info.isConnected() || mobile.isConnected()) {
			return true;
		}
		return false;
	}
	
	/**
	 * 字体着色
	 * @param text 文本
	 * @param color 颜色
	 * @param start 开始位置
	 * @param end 结束位置
	 * @return
	 */
	public static Spannable getSpannableString(String text, int color,
			int start, int end) {
		CharSequence charseq = (CharSequence) text;
		Spannable spanStr = new SpannableString(charseq);
		spanStr.setSpan(new ForegroundColorSpan(color), start, end,
				Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
		spanStr.setSpan(new AbsoluteSizeSpan(26), start, end,
				Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
		return spanStr;
	}
}
